package alarm.imp;

import alarm.ZTextField;
import commons.util.PropertiesUtil;
import gudaziEx.entity.RunningChain;
import gudaziEx.util.ChainUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.text.Document;
import java.util.HashMap;
import java.util.Map;

public class ZtextDoForRunningChainCorn {
    private static final Logger LOGGER = LogManager.getLogger(ZtextDoForRunningChainCorn.class);
    private void doChangeForRunningChainCornString(String corn) {
        RunningChain rc = ChainUtil.getRunningChain();
        rc.setCornString(corn);
        ChainUtil.saveRunningChain(rc);
    }
    public void addWriterFactorListenerForRunningChainCornString(ZTextField zf, Logger LOGGER){
        Document dc =  zf.getDocument();
        dc.addDocumentListener(new DocumentListener() {
            @Override
            public void insertUpdate(DocumentEvent e) {
                doChangeForRunningChainCornString(zf.getText());
            }
            @Override
            public void removeUpdate(DocumentEvent e) {
                doChangeForRunningChainCornString(zf.getText());
            }
            @Override
            public void changedUpdate(DocumentEvent e) {
                LOGGER.info("What?");
            }
        });

    }
}
